package Test;

import static org.junit.Assert.*;

import org.junit.*;

import Spil.*;

public class TestFleet {

	private Ownable fleetSecond;
	private Ownable fleetSea;
	private Ownable fleetBuc;
	private Ownable fleetPrivate;
	private Player player;
	private Player buyer;
	
	@Before
	public void setUp() throws Exception {
      	this.player = new Player("Anders And", 1);
      	this.buyer = new Player("Sorte Per", 1);
      	this.fleetSecond = new Fleet(4000, "Second Sail", 6);
      	this.fleetSea = new Fleet(4000, "Sea Grover", 12);
      	this.fleetBuc = new Fleet(4000, "The Buccaneers", 17);
      	this.fleetPrivate = new Fleet(4000, "Privateer Armade", 21);
      	this.fleetSecond.setOwner(buyer);
      	buyer.addFleetsOwned();
	}
	
	@After
	public void tearDown() throws Exception {
      	this.player = new Player("Anders And", 1);
	}
	
	@Test
	public void testLandOnFleetSecond() {
		int expected = 30000;
		int actual = this.player.bank.getBalance();
      	assertEquals(expected, actual);
      	
      	actual = this.buyer.bank.getBalance();
      	assertEquals(expected, actual);
      	
      	this.fleetSecond.landOnField(this.player);
      	
      	expected = 30000 - 500;
      	actual = this.player.bank.getBalance();
      	assertEquals(expected,actual);
      	
      	expected = 30000 + 500;
      	actual = this.buyer.bank.getBalance();
      	assertEquals(expected,actual);
	}
	
	@Test
	public void testLandOnFleetSea() {
		this.fleetSea.setOwner(buyer);
		buyer.addFleetsOwned();
		
		int expected = 30000;
		int actual = this.player.bank.getBalance();
      	assertEquals(expected, actual);
      	
      	actual = this.buyer.bank.getBalance();
      	assertEquals(expected, actual);
      	
      	this.fleetSecond.landOnField(this.player);
      	
      	expected = 30000 - 1000;
      	actual = this.player.bank.getBalance();
      	assertEquals(expected,actual);
      	
      	expected = 30000 + 1000;
      	actual = this.buyer.bank.getBalance();
      	assertEquals(expected,actual);
	}

	@Test
	public void testLandOnFleetBuc() {
		this.fleetSea.setOwner(buyer);
		buyer.addFleetsOwned();
		this.fleetBuc.setOwner(buyer);
		buyer.addFleetsOwned();
		
		int expected = 30000;
		int actual = this.player.bank.getBalance();
      	assertEquals(expected, actual);
      	
      	actual = this.buyer.bank.getBalance();
      	assertEquals(expected, actual);
      	
      	this.fleetBuc.landOnField(this.player);
      	
      	expected = 30000 - 2000;
      	actual = this.player.bank.getBalance();
      	assertEquals(expected,actual);
      	
      	expected = 30000 + 2000;
      	actual = this.buyer.bank.getBalance();
      	assertEquals(expected,actual);
	}
	
	@Test
	public void testLandOnFleetPrivate() {
		this.fleetSea.setOwner(buyer);
		buyer.addFleetsOwned();
		this.fleetBuc.setOwner(buyer);
		buyer.addFleetsOwned();
		this.fleetPrivate.setOwner(buyer);
		buyer.addFleetsOwned();
		
		int expected = 30000;
		int actual = this.player.bank.getBalance();
      	assertEquals(expected, actual);
      	
      	actual = this.buyer.bank.getBalance();
      	assertEquals(expected, actual);
      	
      	this.fleetPrivate.landOnField(this.player);
      	
      	expected = 30000 - 4000;
      	actual = this.player.bank.getBalance();
      	assertEquals(expected,actual);
      	
      	expected = 30000 + 4000;
      	actual = this.buyer.bank.getBalance();
      	assertEquals(expected,actual);
	}

}
